package com.sunfeng.chap5.selectkey;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

/**
 * 在将通道注册到选择器之前，必须将通道设置成非阻塞模式
 */
public class Test4 {
    public static void main(String[] args) throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        // 核心代码开始
        Selector selector = Selector.open();
        System.out.println("isRegistered="+serverSocketChannel.isRegistered());
        SelectionKey selectionKey = serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
        // 核心代码结束
        System.out.println("isRegistered="+serverSocketChannel.isRegistered());

        serverSocketChannel.close();
    }
}
